package link.anyauto.j2m.util;

import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.PixelFormat;
import android.graphics.drawable.Drawable;

/**
 * Created by voyo on 2016/5/7.
 */
public class ImageUtils {
    public static Bitmap drawableToBitmap(Drawable drawable) {
        Bitmap.Config cnf = drawable.getOpacity() == PixelFormat.OPAQUE ? Bitmap.Config.RGB_565 : Bitmap.Config.ARGB_8888;
        Bitmap bmp = Bitmap.createBitmap(drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight(), cnf);
        drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
        Canvas canvas = new Canvas(bmp);
        drawable.draw(canvas);
        return bmp;
    }
}
